package com.jstyle.beatecg.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Animatable;
import android.os.Bundle;
import android.support.graphics.drawable.AnimatedVectorDrawableCompat;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import com.jstyle.beatecg.R;
import com.jstyle.beatecg.ble.BleManager;
import com.jstyle.beatecg.ble.BleService;
import com.jstyle.beatecg.model.BleData;
import com.jstyle.beatecg.util.RxBus;
import com.jstyle.beatecg.util.SendData;


public class MyAlertDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private OnDialogButtonClickListener listener;
    private boolean cancelable = true;
    private ImageView imageView,iv_dialog_offcon;
    private Button resetting;

    /**
 * @param context
 */ public MyAlertDialog(Context context) {
     super(context, R.style.MyDialogStyle);
     this.context = context;

 }
  @Override protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.dialog_conten); //alertDialog是否可以点击外围消失
        setCanceledOnTouchOutside(cancelable);
        setCancelable(cancelable);
      imageView=this.findViewById(R.id.centimg);
     //摇摆
      Animation rotateAnimation = new RotateAnimation(0, 20, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
      rotateAnimation.setRepeatMode(Animation.REVERSE);
      rotateAnimation.setRepeatCount(Animation.INFINITE);
      rotateAnimation.setDuration(500);
      imageView.setAnimation(rotateAnimation);




         final WindowManager.LayoutParams params = this.getWindow().getAttributes();
         params.gravity = Gravity.CENTER; this.getWindow().setAttributes(params);

      iv_dialog_offcon=this.findViewById(R.id.iv_dialog_offcon);
      iv_dialog_offcon.setOnClickListener(this);

      resetting=this.findViewById(R.id.resetting);

      resetting.setOnClickListener(this);
      this.setCanceledOnTouchOutside(false);
 }
 @Override public void onClick(final View v) {
        switch (v.getId()){
            case R.id.iv_dialog_offcon:
                this.dismiss();
                BleData bleData = new BleData();
                bleData.setAction(BleService.diss);
                RxBus.getInstance().post(bleData);
                BleManager.getInstance().DisConnecte();
                break;
            case R.id.resetting:
                BleManager.getInstance().writeValue(SendData.peidui());
                break;
        }
 }

public interface OnDialogButtonClickListener {
   void onDialogButtonClick(boolean isPositive); }
 }
